home *** CD-ROM | disk | FTP | other *** search
/ New Star Software Collection / NSS_Collection.iso / 3-170 dbase 10 for windows / 1.ima / DOC.PAK / UI_EXTEN.TXT < prev    next >
Text File  |  1993-07-26  |  21KB  |  550 lines

  1.      Copyright (c) 1991-1993 Borland International, Inc.  
  2.                     All Rights Reserved.
  3.  
  4.              THE BLADERUNNER UI LANGUAGE EXTENSIONS
  5.              --------------------------------------
  6. Bladerunner extends the dBASE language with new commands and
  7. functions for creating graphical, event-driven user interfaces.
  8. For compatibility with DOS applications, Bladerunner still
  9. supports the dBASE IV windowing and menu mechanisms. However, to
  10. take full advantage of the Windows environment, you need to
  11. understand and use the new extensions. This document introduces
  12. the new UI extensions and describes the steps for creating and
  13. using windows.
  14.  
  15. Contents
  16. --------
  17.  
  18. I.   Overview
  19. II.  Summary of Steps
  20. III. Step 1 - Define the window
  21. IV.  Step 2 - Define controls
  22. V.   Step 3 - Assign actions
  23. VI.  Step 4 - Read the window
  24. VII. Upgrading dBASE DOS screen forms
  25.  
  26.  
  27. Overview
  28. --------
  29.  
  30. In a Bladerunner application, the window is the primary user
  31. interface container. Windows can contain controls, such as entry
  32. fields and list boxes, for interacting with the user and can also
  33. contain other windows. When you design the user interface for
  34. your application, you are essentially designing its windows.
  35.  
  36. The Bladerunner mechanism for working with windows is familiar to
  37. dBASE IV programmers, with these important differences:
  38.  
  39. - In dBASE IV, there is an active state for GETs (READ) and an
  40.   active state for menus (ACTIVATE MENU/POPUP); both can be
  41.   visible, but only one at a time is active. In Bladerunner,
  42.   there is a single active state for a window. Use READMODAL()
  43.   or OPEN WINDOW to activate GETs (called entry fields), menus,
  44.   and any other controls in the window.
  45.  
  46. - In dBASE IV, only one window at a time can be active. In
  47.   Bladerunner, several windows can be active at once. A new
  48.   command, OPEN WINDOW, displays a window and continues program
  49.   execution, letting you display more windows, or execute other
  50.   code, without stopping execution to get user responses.
  51.  
  52. - In dBASE IV, you DEFINE a window, ACTIVATE it, display your
  53.   SAYs and GETs, then READ. In Bladerunner, you don't ACTIVATE
  54.   windows; instead, you DEFINE the window, DEFINE controls OF
  55.   the window, then READMODAL() or OPEN WINDOW. The next section
  56.   describes these steps in more detail.
  57.  
  58. Summary of Steps
  59. ----------------
  60.  
  61. Below is a summary of the steps for creating and reading a
  62. Bladerunner window. A detailed explanation of each step follows
  63. the summary.
  64.  
  65. 1. Define the window with
  66.  
  67.       DEFINE WINDOW
  68.  
  69. 2. Define controls for the window with
  70.  
  71.       DEFINE <control name> OF <window name>
  72.  
  73. 3. Assign actions with
  74.  
  75.       ON SELECTION WINDOW
  76.       ON SELECTION PULLDOWN
  77.  
  78. 4. Read the window with
  79.  
  80.       READMODAL()  or
  81.       OPEN WINDOW
  82.  
  83. Step 1 - Define the Window
  84. --------------------------
  85.  
  86. DEFINE WINDOW has several options for specifying the look and
  87. behavior of the window. Using these options in different
  88. combinations, you can define input windows, dialog boxes or any
  89. other kind of window. Type HELP DEFINE WINDOW from the Command
  90. Window for a list of options.
  91.  
  92. The Default Font and the Coordinate Plane
  93.  
  94. Each window has a default font which Bladerunner uses to display
  95. any controls or output that don't specify a font. Use the FONT
  96. option of DEFINE WINDOW to set the window's default font. If you
  97. don't use the FONT option, the default font is the Windows system
  98. font.
  99.  
  100. A window's default font is especially important because it
  101. defines the size of the coordinate plane for placing controls in
  102. the window. That is, the row height is determined by the line
  103. height of the default font, and the column width is determined by
  104. the character width of the default font. So, when you issue this
  105. command:
  106.  
  107.    DEFINE TEXT FNHeading OF MyWindow AT 6,16 PROMPT "First Name"
  108.  
  109. Bladerunner displays "First Name" at row 6 (six lines down in the
  110. default font), column 16 (sixteen characters across in the
  111. default font).
  112.  
  113. Proportional fonts, such as Helvetica or Times, have varied
  114. widths for each character: an "i" takes up less space than a "w."
  115. If you specify a proportional font as the default font,
  116. Bladerunner uses the average character width as the column width.
  117. For this reason, using a non-proportional font as the default
  118. window font makes working with window coordinates a little
  119. easier. With a non-proportional default font, you can still
  120. specify proportional fonts for the controls that contain text.
  121. "Specifying Coordinates" in Step 2 describes two new functions,
  122. NEXTROW() and NEXTCOL(), for displaying controls with varied
  123. fonts.
  124.  
  125. Dialog Boxes
  126.  
  127. A dialog box is a window you create for getting information from
  128. the user. The DLGFRAME option of DEFINE WINDOW makes the window's
  129. border look like a standard Windows dialog box, and makes the
  130. window non-sizeable. These other options of DEFINE WINDOW are
  131. useful for creating dialog boxes:
  132.  
  133.  NOMAXIMIZE  Displays the window without a Maximize button.
  134.  NOMINIMIZE  Displays the window without a Minimize button.
  135.  AUTOSIZE    Automatically sets the lower right coordinate of
  136.              the window to contain the lowest and rightmost
  137.              control in the window.
  138.  
  139. This example defines a dialog box for prompting the user to enter
  140. a customer name:
  141.  
  142.  DEFINE WINDOW MyDialog AT 10,10 OF DESKTOP DLGFRAME NOMAXIMIZE;
  143.    NOMINIMIZE AUTOSIZE MESSAGE "Enter a customer name"
  144.  cName = SPACE(30)
  145.  DEFINE TEXT Head1 AT 2,2 OF MyDialog PROMPT "Customer name:"
  146.  DEFINE ENTRYFIELD GetName WITH cName at 2,NEXTCOL() OF MyDialog
  147.  DEFINE PUSHBUTTON Ok AT 4,5 OF MyDialog PROMPT "OK"
  148.  DEFINE PUSHBUTTON Cancel AT 4,NEXTCOL() OF MyDialog ;
  149.    PROMPT "Cancel"
  150.  
  151. Step 2 - Define controls
  152. ------------------------
  153.  
  154. A control is an object you place in a window for interacting with
  155. the user. Bladerunner provides several controls for displaying
  156. and editing data, such as list boxes and radio buttons, and
  157. controls for getting user responses, such as pull-down menus and
  158. pushbuttons. You place a control in a window by defining the
  159. control. Here is the basic syntax:
  160.  
  161.    DEFINE <control name> OF <window name> AT <coordinates>
  162.  
  163. The following examples define controls for MyWindow:
  164.  
  165.    DEFINE TEXT Get1Title OF MyWindow AT 1,5 PROMPT "Enter a name"
  166.    DEFINE ENTRYFIELD Get1 WITH mName OF MyWindow AT 1,20
  167.    DEFINE PUSHBUTTON Push1 OF MyWindow AT 3,2 PROMPT "OK"
  168.    DEFINE LISTBOX List1 OF MyWindow FROM 3,10 TO 9,25 PROMPT FILES
  169.  
  170. Specifying coordinates
  171.  
  172. For precise placement of controls, you can specify coordinates
  173. with decimal values. For example:
  174.  
  175.    DEFINE PUSHBUTTON OK AT 3.5, 1.5 OF MyWindow PROMPT "OK"
  176.  
  177. Controls that contain text, such as entry fields and
  178. radiobuttons, have a FONT option. Even though each control you
  179. place may specify a different font, the coordinates for placing
  180. controls are always based on the window's default font. When
  181. positioning controls with different fonts, the relative
  182. addressing technique commonly used in dBASE DOS, using ROW() and
  183. COL(), can misalign controls. For instance:
  184.  
  185.    @ 1,2       SAY "First line"
  186.    @ ROW()+1,2 SAY "Second line"
  187.    @ ROW()+1,2 SAY "Third line"
  188.  
  189. will display correctly aligned only if all three objects and the
  190. window in which they are displayed use the same font.
  191.  
  192. To accomodate relative addressing with varied fonts, Bladerunner
  193. provides NEXTROW() and NEXTCOL(). NEXTROW() returns the next
  194. available row on the coordinate plane given the last control
  195. drawn; NEXTCOL() returns the next available column. For instance
  196.  
  197.    DEFINE FONT Times10 ........
  198.    @ 2,2             SAY "First line" FONT Times10
  199.    @ NEXTROW(),2     SAY "Second line"  FONT Arial24
  200.    @ NEXTROW(),2     SAY "Third line" FONT Script48
  201.    @ ROW(),NEXTCOL() SAY "Second SAY on Third line" FONT Times10
  202.  
  203. will display correctly aligned regardless of the fonts you
  204. specify.
  205.  
  206.  
  207. Data Controls
  208.  
  209. These controls display and edit data. ENTRYFIELDs correspond to
  210. GETs, and TEXT controls correspond to SAYs.
  211.  
  212. DEFINE...     So a user can
  213. ---------     -------------
  214. ENTRYFIELD    Enter a single value
  215. COMBOBOX      Enter or select one of any number of values
  216. SPINBOX       Enter or select one in an ordered set of values
  217. SCROLLBAR     Select one in an ordered set of values
  218. CHECKBOX      Select one of two logical values
  219. RADIOBUTTONS  Select one of a few values
  220. LISTBOX       Select one or more of any number of values
  221. BROWSE        View or edit fields in a table - tabular view
  222. EDIT          View or edit fields in a table - record view
  223. EDITOR        View or edit text
  224. BOX           See a box
  225. TEXT          See text as a heading, desc., or instruction.
  226. GRAPH         See and interact with a graph of table data
  227. IMAGE         See a bitmapped image
  228.  
  229.  
  230. Action controls
  231.  
  232. These controls, menus, speedbars, and pushbuttons, cause actions
  233. to occur.
  234.  
  235. Bladerunner supports dBASE IV's horizontal bar menus (created
  236. with DEFINE MENU and DEFINE PAD) and popup menus (created with
  237. DEFINE POPUP and DEFINE BAR) only for dBASE IV compatibility. To
  238. create menus in Bladerunner, use these new commands:
  239.  
  240.    DEFINE MENU CHOICE         Defines an item on the menu bar
  241.    DEFINE PULLDOWN            Defines a pulldown menu
  242.    DEFINE PULLDOWN CHOICE     Defines an item on a pulldown menu
  243.    ON MENU CHOICE             Assigns a pulldown menu to a menu
  244.                               bar item
  245.  
  246. A Bladerunner window can have just one menu bar. Consequently,
  247. you don't explicitly define menu bars; you just define each menu
  248. item OF the window with DEFINE MENU CHOICE. The menu items
  249. display in the order you define them on a bar attached to the top
  250. border.
  251.  
  252. Use DEFINE PULLDOWN to define a pull-down menu and DEFINE
  253. PULLDOWN CHOICE to define each item on the pull-down menu. Use ON
  254. MENU CHOICE to attach a pulldown menu to a menu bar item.
  255.  
  256. Menu bars and pulldown menus become active, along with any other
  257. controls in the window, when you read the window.
  258.  
  259. DEFINE MENU CHOICE mFile OF MyWin PROMPT "File"
  260. DEFINE MENU CHOICE mEdit OF MyWin PROMPT "Edit"
  261. ....
  262. DEFINE PULLDOWN pFile
  263. DEFINE PULLDOWN CHOICE pFile1 OF pFile PROMPT "Delete"
  264. DEFINE PULLDOWN CHOICE pFile2 OF pFile PROMPT "Recall"
  265. ....
  266. ON MENU CHOICE mFile OF MyWin ACTIVATE PULLDOWN pFile
  267. ....
  268.  
  269. A speedbar is a row or column of related buttons that cause an
  270. action when pressed. In Windows applications, speedbars typically
  271. duplicate menu items, offering a quick way to cause an action
  272. without having to find it on a menu. For instance, Print can be
  273. an item on the File menu and also a button on the speedbar.
  274.  
  275. Use DEFINE SPEEDBAR to create a speedbar definition and DEFINE
  276. SPEEDBUTTON to define each button on the speedbar. DEFINE
  277. SPEEDBUTTON has an EXECUTE option for specifying a command or
  278. subroutine to run when the button is pressed.
  279.  
  280. Note: In this Alpha release, speedbars are not yet implemented.
  281.  
  282. A pushbutton is a single button that causes an action when
  283. pressed. For instance, an OK pushbutton can save and exit from a
  284. window, and a Cancel pushbutton can exit without saving.
  285. Typically, pushbuttons confirm an entry or selection made in
  286. other controls. Use DEFINE PUSHBUTTON to define pushbuttons.
  287.  
  288. In Windows applications, if a window has a menu, the menu
  289. typically offers an item for exiting the window. If a window has
  290. no menu, push buttons (such as Cancel or Ok) typically exit the
  291. window. A window should not contain both push buttons and menu
  292. items for exiting.
  293.  
  294.  
  295. Step 3 - Assign actions
  296. -----------------------
  297.  
  298. You can assign actions to pull-down menu items, push buttons, and
  299. to the window itself. Assigning actions to menus is similar to
  300. dBASE IV. To assign actions to push buttons and windows, you need
  301. to understand a new concept of window selection.
  302.  
  303. Pulldown Menus
  304.  
  305. Assign actions to pull-down menus with ON SELECTION PULLDOWN.
  306. Typically, ON SELECTION PULLDOWN calls a procedure that uses
  307. CHOICE() or PROMPT() to determine which item was selected, then
  308. branches to other commands based on the selection.
  309.  
  310. Window Selection
  311.  
  312. Selecting a window accepts changes made to the window's controls,
  313. much like Ctrl-W accepts values in dBASE DOS.
  314.  
  315. A user selects a window by:
  316. - Clicking on a pushbutton
  317. - Pressing Enter when the cursor is in the window (See Enter key
  318.   behavior in Step 4 for details.)
  319. - Pressing Ctrl-Enter
  320.  
  321. A user exits a window without selecting it by:
  322. - Pressing Esc. You can prevent this with the NoEscape option of
  323.   OPEN WINDOW, or passing a logical escape parameter to
  324.   READMODAL().
  325. - Double-clicking in the window's control box, or selecting
  326.   Close from the control menu, if the window has a control box.
  327. - Pressing Ctrl-F4.
  328.  
  329. Use ON SELECTION WINDOW to specify a procedure to execute when a
  330. window is selected.
  331.  
  332. Typically, if a window contains one or more push buttons, the ON
  333. SELECTION WINDOW procedure uses ACTIVECONTROL() to determine
  334. which push button was pressed, then branches to other commands.
  335. Push buttons differ from other controls in that one push button
  336. is always chosen when the user selects the window. The chosen
  337. push button is either the one the user presses, or the default
  338. push button if none is pressed.
  339.  
  340.  
  341. Trapping keystrokes
  342.  
  343. You can assign actions to keystrokes, using the familiar dBASE
  344. DOS command, ON KEY. However, certain keystroke combinations are
  345. common to all Windows applications. For instance, Alt-F4 closes
  346. the active window or dialog box. Your application should not map
  347. other behavior to these reserved key combinations.
  348.  
  349.  
  350. Step 4 - Read the window
  351. ------------------------
  352.  
  353. Bladerunner provides two methods for reading windows: READMODAL()
  354. and OPEN WINDOW.
  355.  
  356. READMODAL()
  357.  
  358. Use READMODAL( <window name> ) to stop program execution and read
  359. a window. READMODAL() performs a "modal" read of a window. That
  360. is, it activates the window with exclusive focus -- the user
  361. cannot change focus to another window without first exiting the
  362. READMODAL() window.
  363.  
  364. You can use READMODAL() in a command line the same way you would
  365. use other fuctions, like GETFILE(), that display a dialog box and
  366. return a value. By default, READMODAL() returns the name of the
  367. control that has focus when the user selects the window. (See
  368. "Window Selection" in Step 3.) You can query the READMODAL()
  369. return value to determine the user's action.
  370.  
  371.   DEFINE WINDOW Alert FROM 5,5 to 20,65 OF DESKTOP
  372.   DEFINE PUSHBUTTON Ok OF Alert at 2,2 PROMPT "OK"
  373.   DEFINE PUSHBUTTON Cancel OF Alert at 2,14 PROMPT "Cancel"
  374.   ReturnVal = ReadModal("Alert")
  375.  
  376.   IF ReturnVal = "OK"
  377.      DO OKProc
  378.   ELSE
  379.      DO CancelProc
  380.   ENDIF
  381.  
  382. You can specify your own return value for READMODAL() using the
  383. WITH option of CLOSE WINDOW. This makes it easy to re-use your
  384. window and dialog box definitions. The following example displays
  385. the Alert window and returns "My return value."
  386.  
  387.   DEFINE WINDOW Alert FROM 5,5 to 20,65 OF DESKTOP
  388.   DEFINE PUSHBUTTON Ok OF Alert at 2,2 PROMPT "OK"
  389.   DEFINE PUSHBUTTON Cancel OF Alert at 2,14 PROMPT "Cancel"
  390.   ON SELECTION WINDOW Alert CLOSE WINDOW WITH "My return value"
  391.   ReturnVal = ReadModal("Alert")
  392.  
  393. You can nest READMODAL() statements. For instance, a window
  394. displayed with READMODAL() can contain a push button that
  395. launches another READMODAL() window. In this case, the user must
  396. exit the second window, then the first window, before switching
  397. focus to another window.
  398.  
  399. OPEN WINDOW
  400.  
  401. OPEN WINDOW performs a "non-modal" read of a window; the user can
  402. switch focus to another window without exiting the current
  403. window. Choose OPEN WINDOW over READMODAL() when you want to have
  404. more than one window active simultaneously.
  405.  
  406. Also, unlike READMODAL(), OPEN WINDOW does not stop program
  407. execution. This allows you to execute more OPEN WINDOW commands,
  408. or any other code, after reading a window.
  409.  
  410. While OPEN WINDOW represents a break from traditional dBASE
  411. coding techniques, where READ commands temporarily halt
  412. execution, it allows you to design true event-driven
  413. applications. A typical event-driven application simply sets up
  414. the environment, and creates and displays its windows. Further
  415. execution is determined by the user.
  416.  
  417. Having execution continue after OPEN WINDOW, raises certain
  418. issues your program needs to handle. Here are the issues with our
  419. current recommendations (better solutions should follow this
  420. Alpha release -- your suggestions are encouraged!):
  421.  
  422. - As always occurs in dBASE, non-PUBLIC memory variables are
  423.   released when the program they are declared in finishes
  424.   executing. So, if a program creates a window, assigns some
  425.   memory variables, reads the window with OPEN WINDOW, then ends,
  426.   the variables are released even though the window is now
  427.   active. To avoid releasing these variables, you can declare
  428.   them PUBLIC.
  429.  
  430. - If you define controls that are based on fields in a table (for 
  431.   example, a GET or ENTRYFIELD using a field name), then read the
  432.   window with OPEN WINDOW, then close the table, the controls will
  433.   not work because the table is no longer in use. Make sure you 
  434.   don't close the table until the window is closed.
  435.  
  436. - As always occurs in dBASE, functions and procedures declared in
  437.   a program are unavailable when the program finishes executing.
  438.   So, if a program contains function declarations, assigns these
  439.   functions to event handlers such as a VALID or OnClosed option,
  440.   then reads the window with OPEN WINDOW, the functions are not
  441.   available when the program ends, even though the window may
  442.   still be active. To make sure all subroutines attached to event
  443.   handlers remain available, declare them in a common procedure
  444.   file that always stays open.
  445.  
  446.  
  447. The following example shows how you can use OPEN WINDOW to read
  448. two windows. The user can launch Calc.prg to activate the
  449. Calculator, then launch Invoice.prg to activate the Invoice
  450. window. Both windows are then available, and the user can switch
  451. focus between them.
  452.  
  453.   * Calc.prg - a calculator
  454.   DEFINE WINDOW Calculator FROM 10,2
  455.   * DEFINE controls OF Calulator
  456.   ....
  457.   OPEN WINDOW Calculator             && Reads Calculator
  458.   * More code here, if necessary
  459.   ....
  460.   RETURN
  461.  
  462.   * Invoice.prg - entry window for an invoice
  463.   DEFINE WINDOW Invoice FROM 1,1
  464.   * DEFINE controls OF Invoice
  465.   ....
  466.   OPEN WINDOW Invoice               && Reads Invoice
  467.   * More code here, if necessary
  468.   ....
  469.   RETURN
  470.  
  471.  
  472. Enter key behavior
  473.  
  474. One of the differences between dBASE DOS and Windows applications
  475. is the behavior of the Enter key. In dBASE DOS, pressing the
  476. Enter key moves the cursor to the next GET; pressing Enter on the
  477. last GET terminates the READ. In Windows applications, the Tab
  478. key typically moves to the next control. Pressing Enter accepts
  479. the controls much like Ctrl-W does in dBASE DOS.
  480.  
  481. In Bladerunner, pressing Enter when the cursor is in the window
  482. body, but not in an editor object, accepts and exits the window.
  483. Tab and Shift-Tab move the cursor to the next and previous
  484. controls respectively.
  485.  
  486. While the Windows Enter key behavior is preferable in a Windows
  487. application, you might want to retain the DOS behavior to
  488. maintain consistency with your DOS applications. Bladerunner
  489. provides SET CUAENTER to specify the behavior of the Enter key.
  490. SET CUAENTER OFF causes the Enter key to behave as in dBASE DOS;
  491. SET CUAENTER ON follows the Windows behavior.
  492.  
  493. Ctrl-Enter accepts and exits and window regardless of the SET
  494. CUAENTER setting.
  495.  
  496. Upgrading dBASE DOS screen forms
  497. --------------------------------
  498.  
  499. The Bladerunner UI language extensions replace the familiar dBASE
  500. DOS @...SAY/GET commands with the new DEFINE commands, DEFINE
  501. TEXT and DEFINE ENTRYFIELD. But that doesn't mean you have to
  502. stop using @...SAY/GET. To help you upgrade your dBASE DOS screen
  503. forms, Bladerunner provides two new commands, SET WINDOW TO
  504. <window name> and SET WINDOW ON. These commands direct
  505. @...SAY/GET output to <window name>. You can then define new
  506. controls for <window name> without re-writing your @...SAY/GETs.
  507.  
  508. Follow these steps:
  509.  
  510. 1.If your screen form is displayed in a window, consider adding
  511.   some of the Bladerunner options to your DEFINE WINDOW command,
  512.   such as DLGFRAME or AUTOSIZE. Otherwise, define a new window.
  513.  
  514. 2.Replace the ACTIVATE WINDOW command with SET WINDOW TO
  515.   <window name> and SET WINDOW ON.
  516.  
  517. 3.Define any new controls you want to add to your form.
  518.  
  519. 4.If you activate your form with SET FORMAT TO, remove that
  520.   line. Instead, run the format file like a program, as DO
  521.   <format file name>.
  522.  
  523. 5.Replace the READ command with READMODAL().
  524.  
  525. Here is a sample dBASE DOS screen form (Assume an open table
  526. contains the fields, FName, LName, and Color):
  527.  
  528.  
  529. DEFINE WINDOW SelColor FROM 1,1 to 12,50
  530. ACTIVATE WINDOW SelColor
  531. @ 2,10 SAY "First Name" GET FName
  532. @ 4,10 SAY "Last Name"  GET LName
  533. @ 6,10 SAY "Color choice" GET Color
  534. READ
  535.  
  536. Here is the same screen form upgraded to Bladerunner:
  537.  
  538. DEFINE WINDOW SelColor FROM 1,1 AUTOSIZE
  539. SET WINDOW TO SelColor
  540. SET WINDOW ON
  541. @ 2,10 SAY "First Name" GET FName
  542. @ 4,10 SAY "Last Name   GET LName
  543. DEFINE RADIOBUTTON RadioClr WITH Color OF SelColor AT 6,23;
  544.      PROMPT "Red" PICK "R", "Green" PICK "G", "Blue" PICK "B";
  545.      HORIZONTAL
  546. READMODAL("SelColor")
  547.  
  548.  
  549. ------------------------> EOF: UI_exten.TXT <--------------------
  550.